package controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import vo.ScheduleVO;
import dto.ScheduleDTO;

public class ScheduleTeamTodayInsertController extends HttpServlet {
	
	public ScheduleTeamTodayInsertController() {
		
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		req.setCharacterEncoding("utf-8");
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		req.setCharacterEncoding("utf-8");

		String m_id = (String)req.getParameter("m_id");
 		String schedule_date = (String)req.getParameter("schedule_date");
 		String schedule_time = (String)req.getParameter("schedule_time");
		String schedule_today_contents = (String)req.getParameter("schedule_today_contents");
		String schedule_division = (String)req.getParameter("schedule_division");
		String year = schedule_date.substring(0, 4);
		String month = schedule_date.substring(4, 6);
		String date = schedule_date.substring(6, 8);
		
		int integer_Month = Integer.parseInt(month);
		month = String.valueOf(integer_Month-1);
		
		System.out.println("-------------------[Controller 오늘의 팀 일정] 컨텐츠를 입력 합니다.-------------------");
		System.out.println("m_id: "+m_id);
		System.out.println("date: "+schedule_date);
		System.out.println("time: "+schedule_time);
		System.out.println("year: "+year);
		System.out.println("month: "+month);
		System.out.println("date: "+date);
		System.out.println("schedule_today_contents: "+schedule_today_contents);
		System.out.println("division: "+schedule_division);
		System.out.println("-----------------------------------------------------------------------------");		
		
		ScheduleDTO dto = new ScheduleDTO();
		ScheduleVO vo = new ScheduleVO();
		vo.setM_id(m_id);
		vo.setSchedule_date(schedule_date);
		vo.setSchedule_time(schedule_time);
		vo.setSchedule_today_contents(schedule_today_contents);
		vo.setSchedule_division(schedule_division);
		
		boolean flag_team_today_insert = dto.teamTodayInsert(vo);
		
		req.setAttribute("flag_team_today_insert", flag_team_today_insert);
		resp.sendRedirect("/group2/index/main.jsp?inc=../schedule/schedule_team_today.jsp?date="+date+"&month="+month+"&year="+year+"&action=2&left_menu=../schedule/schedule_menu.jsp");
	}
}
